package com.cskaoyan.service.wx;


import com.cskaoyan.bean.po.MarketCategory;
import com.cskaoyan.bean.po.MarketCategoryExample;
import com.cskaoyan.bean.wx.category.WxCatalogCurrentVo;
import com.cskaoyan.bean.wx.category.WxCatelogIndexVo;
import com.cskaoyan.mapper.MarketCategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WxCatelogServiceImpl implements  WxCatelogService {

    @Autowired
    MarketCategoryMapper marketCategoryMapper;

    @Override
    public WxCatelogIndexVo queryAll() {
        MarketCategoryExample example = new MarketCategoryExample();

        MarketCategoryExample.Criteria criteria = example.createCriteria();

        criteria.andLevelEqualTo("L1");

        List<MarketCategory> marketCategories = marketCategoryMapper.selectByExample(example);

        MarketCategoryExample example1 = new MarketCategoryExample();

        MarketCategoryExample.Criteria criteria1 = example1.createCriteria();

        criteria1.andLevelEqualTo("L2");

        List<MarketCategory> marketCategories1 = marketCategoryMapper.selectByExample(example1);

        MarketCategory marketCategory = marketCategories.get(0);

        WxCatelogIndexVo wxCatelogIndexVo = new WxCatelogIndexVo();

        wxCatelogIndexVo.setCurrentCategory(marketCategory);
        wxCatelogIndexVo.setCategoryList(marketCategories);
        wxCatelogIndexVo.setCurrentSubCategory(marketCategories1);

        return wxCatelogIndexVo;
    }

    @Override
    public WxCatalogCurrentVo queryAllById(Integer id) {

        MarketCategory marketCategory = marketCategoryMapper.selectByPrimaryKey(id);

        MarketCategoryExample example = new MarketCategoryExample();

        MarketCategoryExample.Criteria criteria = example.createCriteria();

        criteria.andPidEqualTo(marketCategory.getId());

        List<MarketCategory> marketCategories = marketCategoryMapper.selectByExample(example);

        WxCatalogCurrentVo wxCatalogCurrentVo = new WxCatalogCurrentVo();
        wxCatalogCurrentVo.setCurrentCategory(marketCategory);
        wxCatalogCurrentVo.setCurrentSubCategory(marketCategories);
        return wxCatalogCurrentVo;
    }


}
